package com.xinhe.cn.cpbox.controller;

import com.xinhe.cn.cpbox.common.Result;
import com.xinhe.cn.cpbox.entity.dto.PayDto;
import com.xinhe.cn.cpbox.mapper.UserOrderMapper;
import com.xinhe.cn.cpbox.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Objects;

/**
 * @author HB
 * @date 2021/10/09 11:31
 */
@Api(value = "H5端支付接口", tags = {"H5端支付接口"})
@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    PayService payService;

    /**
     * @param request
     * @return
     */
    @ApiOperation(value = "H5生成调至支付所需参数接口", notes = "H5生成调至支付所需参数接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "消费者的openId", dataTypeClass = String.class),
            @ApiImplicitParam(name = "money", value = "消费金额，单位为分", dataTypeClass = String.class),
            @ApiImplicitParam(name = "orderName", value = "商品名：成为月老，抽取纸条，放入纸条", dataTypeClass = String.class)
    }
    )
    @PostMapping("/getOrder")
    public Map<String, String> getOrder(HttpServletRequest request, @RequestBody PayDto payDto) {
        return payService.getOrder(request, payDto);
    }


    @RequestMapping("/callback")
    public String callBack(HttpServletRequest request, HttpServletResponse response) {
        return payService.callBack(request, response);
    }
}
